package yxy.cherry.battle.module.affix.skill;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.PropertyType;
import yxy.cherry.battle.module.TriggerPoint;
import yxy.cherry.battle.module.affix.AffixContext;
import yxy.cherry.battle.module.affix.AffixFactory.SkillTypeEnum;
import yxy.cherry.battle.module.affix.Skill;
import yxy.cherry.battle.module.affix.SkillType;
import yxy.cherry.battle.module.record.stream.RecordStream42TriggerSkill;
import yxy.cherry.battle.module.record.stream.RecordStreamGroup;
import yxy.cherry.battle.module.record.stream.RecordStream_SKL;
import yxy.cherry.data.bean.skill;

import java.util.Collection;

/** 强化追攻 */
@SkillType(Type = SkillTypeEnum.强化追攻)
public class Affix_30_强化追攻 extends Skill {

    private int get伤害比例() {
        return getParam(0);
    }

    public Affix_30_强化追攻(Fighter actor, skill skilldata, int probability, int[] params) {
        super(actor, skilldata, probability, params);
    }

    private RecordStreamGroup steamGroup;

    @Override
    public RecordStreamGroup record() {
        steamGroup = getRecord().stream(new RecordStreamGroup());
        steamGroup.add(new RecordStream_SKL(getActor(), getSkillId()));
        return steamGroup;
    }

    @Override
    public boolean _exec(Collection<Fighter> targets) {
        if (getAffixContext().is附加行动中()) {
            return false;
        }
        if (!isEffectiveOne(getActor())) {
            return false;
        }
        boolean 有活人 = false;
        if (targets.size() <= 0) {
            for (Fighter target : getActor().getTeam().getTeam对手().getFighters()) {
                if (target.is活着()) {
                    有活人 = true;
                    break;
                }
            }
        } else {
            for (Fighter target : targets) {
                if (target.is活着()) {
                    有活人 = true;
                    break;
                }
            }
        }
        if (!有活人) {
            return false;
        }

//		AffixAction action = getAffixContext().add附加行动(getActor(), targets, AffixActionClass.追加攻击);
//		getRecord().stream(new RecordStream42TriggerSkill(getActor(),501)).record();
//		action.set附加比例(get伤害比例());
        //保存攻击力
        long value = getActor().getData().getPropertyData().getValue(PropertyType.P_攻击);
        test追攻();
        //归还攻击力
        getActor().getData().getPropertyData().setValue(PropertyType.P_攻击,value);
        Battle.battleLogger(6,"追攻：追攻者："+getActor()+"伤害比例："+get伤害比例());

        return true;
    }

    public void test追攻(){
        Collection<Fighter> targetWJ = target(getActor());
//        TargetSelector_25_血量排序 target_test = new TargetSelector_25_血量排序();
//        Set<Fighter> targetWJ = target_test.target(getActor(), getActor().getTeam().getTeam对手(), 0, 1);
        if(targetWJ==null||targetWJ.size()==0){
            return ;
        }
        getRecord().stream(new RecordStream42TriggerSkill(getActor(),501)).record();
        AffixContext.AffixAction action = getAffixAction();
        action.set行动者(getActor());
        action.setTargets(targetWJ);
        action.add行动类型(AffixContext.AffixActionClass.追加攻击);
        action.set附加比例(get伤害比例());
        getActor().handle普攻();
        getActor().trigger(TriggerPoint.攻后);
        //减少攻击力
        long value = getActor().getData().getPropertyData().getValue(PropertyType.P_攻击);
        int[] params = getParams();
        if(params[1] == VALUE_比率分母){
            value = 0;
        }else{
            value = value * (VALUE_比率分母 - params[1])/VALUE_比率分母;
        }
        getActor().getData().getPropertyData().setValue(PropertyType.P_攻击,value);
        for (Fighter fighter : targetWJ) {
            boolean 活着 = fighter.is活着();
            if (活着){
                return;
            }
        }
        test追攻();
    }


    @Override
    public boolean exec(Fighter actor, Fighter target) {
        return true;
    }

}